package com.wy2.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wy2.entity.Clock;
import com.wy2.mapper.ClockMapper;
import com.wy2.service.ClockService;
import com.wy2.util.FenyeUtil;

@Service
public class ClockServiceImpl implements ClockService {

	
	@Autowired
	private ClockMapper cm;
	
	// 获取当前时间 当做打开时间
 	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    // 获取当前时间 当做打开时间
 	private SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd");

 	/**
	 * 添加打卡用户
	 */
	@Override
	public Integer addClock(Clock u) {
		u.setCheckintime(sdf.format(new Date()));
		u.setCstatus("已打卡");
		return cm.addClock(u);
	}

	/**
	 * 修改签退时间和状态
	 */
	@Override
	public Integer upClock(Clock u) {
//		System.out.println("-----impl"+u);
//		Clock cheUsers = cm.getUsers(u.getUid(), sdfs.format(new Date()));
//		System.out.println("==="+cheUsers);
//		System.out.println("cid"+cheUsers.getCid());
//		u.setCheckoutime(sdf.format(new Date()));
//		u.setCstatus("已签退");
//		u.setCid(cheUsers.getCid());
		return cm.upClock(u);
	}

	/**
	 * 显示所有+分页
	 */
	@Override
	public FenyeUtil<Clock> getAllUchecks(FenyeUtil<Clock> fenye) {
		List<Clock> data = cm.getAllUchecks(fenye);
		Integer count = cm.getCount(fenye);
		if(data.size() > 0) {
			//设置参数
			fenye.setCount(count);
			fenye.setData(data);
		} else {
			fenye.setCode(1);
			fenye.setMsg("无数据");
		}
		return fenye;
	}

	@Override
	public List<Clock> getTimelast(Clock u) {
		// TODO Auto-generated method stub
		return cm.getTimelast(u);
	}

	@Override
	public Integer importSingin(Clock s) {
		// TODO Auto-generated method stub
		return cm.importSingin(s);
	}

}
